<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <include file="./Application/Admin/View/Include/easyui.html" />
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/Admin/css/init.css">
</head>

<body>

    <div class="easyui-tabs" style="width:100%;">

        <div title="管理员管理" style="padding:10px">

            <table id="admin" class="easyui-datagrid" title="管理员列表" style="width:100%;"

            data-options="singleSelect:true,pagination:true,collapsible:false,url:'__APP__/Admin/get_admin',method:'post'"
            toolbar="#tb"
            footer="#fb"
            fitColumns="true">
            <thead>                           
                <tr>
                    <th data-options="field:'id'" width="5%">ID</th>
                    <th data-options="field:'username'" width="10%">用户名</th>
                    <th data-options="field:'tname'" width="10%">真实姓名</th>
                    <th data-options="field:'email'" width="15%">用户邮箱</th>
                    <th data-options="field:'loginip'" width="10%">最后登录IP</th>
                    <th data-options="field:'last_login_time'" width="15%">最后登录时间</th>
                    <th data-options="field:'telphone'" width="10%">联系方式</th>

                    <th data-options="field:'status',formatter:formatNav" width="5%">状态</th>
                </tr>
            </thead>
            </table>

            <div id="tb" style="padding:2px;">
                <button class="easyui-linkbutton" plain="true" iconCls="icon-add" onclick="addAdmin()">添加管理员</button>

                <button class="easyui-linkbutton" plain="true" iconCls="icon-edit" onclick="editAdmin()">编辑管理员</button>
                <button class="easyui-linkbutton" plain="true" iconCls="icon-delete" onclick="delAdmin()">删除管理员</button>
                <button class="easyui-linkbutton" plain="true" iconCls="icon-refresh" onclick="javascript:$('#admin').datagrid('reload')">刷新</button>
            </div>

        </div>

    </div>

    <!--  栏目表单Dialog  -->
    <div id="dlg" class="easyui-dialog" style="width:50%;height:300px;padding:10px 0px; text-align:center;"
    closed="true" buttons="#dlg-buttons">
    <form id="fm" method="post" novalidate>
        <div id="un" class="fitem">
            <label>用户名:</label>
            <input name="username" class="easyui-textbox" required="true">
        </div>
        <div class="fitem">
            <label>真实姓名:</label>
            <input name="tname" class="easyui-textbox" required="true">
        </div>
        <div class="fitem">
            <label>密码:</label>
            <input  name="pwd" value="default"  type="password" class="easyui-textbox" required="true" >

        </div> 
        <div class="fitem">
            <label>确认密码:</label>
            <input  name="truepassword" value="default"  type="password" class="easyui-textbox" required="true" >
        </div> 
        <div class="fitem">
            <label>手机号码:</label>
            <input name="telphone" class="easyui-textbox" required="true">
        </div>
        <div class="fitem">
            <label>E-email:</label>
            <input name="email" class="easyui-textbox" required="true">
        </div>
        <div id="perm" class="fitem">
            <label>拥有权限:</label>
            <input id="permname" name="perm[]" class="easyui-combobox"
            data-options="valueField:'id',textField:'name',url:'__APP__/Perm/get_perm_select',multiple:true">
        </div>

        <div class="fitem">
            <label>是否可用:</label>
            <select name="status" class="easyui-combobox" required="true" style="width:80px;">
                <option value="1">可用</option>
                <option value="0">不可用</option>
            </select>
        </div>
    </form>
    </div>


    <div id="dlg-buttons">
        <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="saveExtend()" style="width:90px">Save</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')" style="width:90px">Cancel</a>
    </div>


<script>

    var url;

    function addAdmin(){
        $('#dlg').dialog('open').dialog('setTitle','添加管理员');
        $('#fm').form('clear');
        url = '__APP__/Admin/add';
    }

    function editAdmin(){
        var row = $('#admin').datagrid('getSelected')
        if (row){
                $("#un").hide();//用户名不给修改 
                if(row.super==1){
                    $("#site").hide();
                    $("#bb").show();  
                }

                $('#dlg').dialog('open').dialog('setTitle','编辑管理员'); 
                $('#fm').form('load',row);
                $('#permname').combobox('setValues',row.perm.split(','))
                ;
                url = '__APP__/Admin/edit/id/'+row.id;
                
            }else{
                $.messager.alert('警告','请选择要编辑的记录');
            }
        }
        
        function delAdmin(){
            var row = $('#admin').datagrid('getSelected');
            if (row){
                $.messager.confirm('确认删除','确认删除吗?',function(r){
                    if (r){
                        $.post('__APP__/Admin/del',{id:row.id},function(result){
                            if (result.success){
                                $('#admin').datagrid('reload');
                            } else {
                                $.messager.alert('警告',result.errorMsg);
                            }
                        },'json');
                    }
                });
            }else{
                $.messager.alert('警告','请选择要编辑的记录');
            }
        }
        
        function saveExtend() {
            $('#fm').form('submit',{
                url: url,
                onSubmit: function(){
                    return $(this).form('validate');
                },
                success: function(result){

                    var result = (eval('('+result+')').errorMsg);

                    if (result){
                       $.messager.alert('警告',result);
                   } else {
                    $('#dlg').dialog('close');
                    $('#f').dialog('close');
                    $('#admin').datagrid('reload')
                }
            }
        });
        }
        
        //状态
        function formatNav(val,row) {
            if (val == 1) return "<span style='color:red;'>可用</span>";
            return "不可用";
        }


    </script>

</body>
</html>